//
//  ViewController.swift
//  TableViewSwiftApp
//
//  Created by GeIL on 16/6/24.
//  Copyright © 2016年 CX. All rights reserved.
//

import UIKit

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{

    var tableData = [String]()
    
    

   
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    
        for count in 0...10{
            
            tableData.append("Item \(count)")
        }
        
          print("The table Data arrays \(tableData)")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
 
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return tableData.count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
         let cell = tableView.dequeueReusableCellWithIdentifier("CellIndentifier", forIndexPath: indexPath)
    
        cell.textLabel!.text = tableData[indexPath.row]
        return cell
    }
 
    
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        let messgeString = "You trapped row \(indexPath.row)"
        
        let alertController = UIAlertController(title: "row tapped", message: messgeString, preferredStyle: .Alert)
        
        let okAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
    
        alertController.addAction(okAction)
        
        self.presentViewController(alertController, animated: true) { 
            print("\(messgeString)")
        }
        
    }
    
    
    
}

